package cn.legend.travel.tour.team.elasticsearch;

import cn.legend.travel.common.pojo.vo.PageData;
import cn.legend.travel.tour.team.dao.search.TourElasticSearchRepository;
import cn.legend.travel.tour.team.pojo.po.TourSearchPO;
import cn.legend.travel.tour.team.pojo.vo.TourSearchVO;
import cn.legend.travel.tour.team.service.ITourService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class ElasticSearchTest2 {
    @Autowired
    TourElasticSearchRepository repository;
    @Autowired
    ITourService tourService;

    @Test
    void save() {
        String test = "测试数据1";
        TourSearchPO tourSearchPO = new TourSearchPO();
        tourSearchPO.setId(1000L);
        tourSearchPO.setDeparture(test);
        tourSearchPO.setType(test);
        repository.save(tourSearchPO);

    }

    @Test
    void rebuild() {
        tourService.rebuildSearch();
        System.out.println("数据重建完成");
        repository.findAll();
        System.out.println("数据查询完成");
    }

    @Test
    void findAll() {
        Iterable<TourSearchPO> all = repository.findAll();
        System.out.println("数据查询完成");
        for (TourSearchPO tourSearchPO : all) {
            System.out.println(tourSearchPO);
        }
    }

    @Test
    void keywordSearch() {
        String keyword = "优秀导游耐心解说";
        String keyword1 = "云南昆明大理丽江";
        PageData<TourSearchVO> pageData = tourService.search(keyword,keyword1, 1);
        List<?> list = pageData.getList();
        System.out.println("搜索结果记录数：" + list.size());
        for (Object item : list) {
            System.out.println(item);
        }

    }
    void single(){
       String s = "{\n" +
               "  \"query\": {\n" +
               "    \"match\": {\n" +
               "      \"type\": \"?0\"\n" +
               "    }\n" +
               "  }\n" +
               "}";
       String a = "{\n" +
               "    \"bool\": {\n" +
               "      \"should\": [\n" +
               "        {\n" +
               "          \"match\": {\n" +
               "            \"store\": \"?0\"\n" +
               "          }\n" +
               "        },\n" +
               "        {\n" +
               "          \"match\": {\n" +
               "            \"type\": \"?0\"\n" +
               "          }\n" +
               "        },\n" +
               "        {\n" +
               "          \"match\": {\n" +
               "            \"title\": \"?0\"\n" +
               "          }\n" +
               "        },\n" +
               "        {\n" +
               "          \"match\": {\n" +
               "            \"departure\": \"?0\"\n" +
               "          }\n" +
               "        },\n" +
               "        {\n" +
               "          \"match\": {\n" +
               "            \"keywords\": \"?0\"\n" +
               "          }\n" +
               "        }\n" +
               "      ]\n" +
               "    }\n" +
               "  }";
    }
}
